import type { CSSProperties } from "react";
import type { ButtonProps } from "antd/es/button";
import type { RowProps } from "antd";
import type { FieldMapToTime, FormSchema, FormProps, FormActionType } from "./types/form";
import type { ColEx } from "./types";
import type { TableActionType } from "@/components/Table";

export interface BasicPropsType {
	// 标签宽度  固定宽度
	labelWidth?: number | string;
	fieldMapToTime?: FieldMapToTime;
	compact?: boolean;
	// 表单配置规则
	schemas?: FormSchema[];
	mergeDynamicData?: Recordable;
	baseRowStyle?: CSSProperties;
	baseColProps?: Partial<ColEx>;
	autoSetPlaceHolder?: boolean;
	// 在INPUT组件上单击回车时，是否自动提交
	autoSubmitOnEnter?: boolean;
	submitOnReset?: boolean;
	submitOnChange?: boolean;
	size?: string;
	// 禁用表单
	disabled?: boolean;
	emptySpan?: number | Recordable;
	// 是否显示收起展开按钮
	showAdvancedButton?: boolean;
	// 转化时间
	transformDateFunc?: Fn;
	rulesMessageJoinLabel?: boolean;
	// 超过3行自动折叠
	autoAdvancedLine?: number;
	// 不受折叠影响的行数
	alwaysShowLines?: number;
	// 是否显示操作按钮
	showActionButtonGroup?: boolean;
	// 操作列Col配置
	actionColOptions?: Partial<ColEx>;
	// 显示重置按钮
	showResetButton?: boolean;
	// 是否聚焦第一个输入框，只在第一个表单项为input的时候作用
	autoFocusFirstItem?: boolean;
	// 重置按钮配置
	resetButtonOptions?: Partial<ButtonProps>;
	// 显示确认按钮
	showSubmitButton?: boolean;
	// 确认按钮配置
	submitButtonOptions?: Partial<ButtonProps>;
	// 自定义重置函数
	resetFunc?: () => Promise<void>;
	submitFunc?: () => Promise<void>;
	// 以下为默认props
	hideRequiredMark?: boolean;
	labelCol?: Partial<ColEx>;
	layout?: string;
	tableAction?: TableActionType;
	wrapperCol?: Partial<ColEx>;
	colon?: boolean;
	labelAlign?: string;
	rowProps?: RowProps;
	// 表单默认值
	initialValues?: Recordable;
}

export const BasicPropsDefault = {
	initialValues: {},
	labelWidth: 0,
	schemas: [],
	autoSetPlaceHolder: true,
	autoSubmitOnEnter: false,
	size: "default",
	emptySpan: 0,
	transformDateFunc: (date: any) => date?.format?.("YYYY-MM-DD HH:mm:ss") ?? date,
	rulesMessageJoinLabel: true,
	autoAdvancedLine: 3,
	alwaysShowLines: 1,
	showActionButtonGroup: false,
	showResetButton: true,
	showSubmitButton: true,
	layout: "horizontal"
};

export type ButtonOptions = Partial<ButtonProps> & { text: string };

export interface ActionPropsType {
	showActionButtonGroup: Boolean;
	showResetButton: Boolean;
	showSubmitButton: Boolean;
	showAdvancedButton: Boolean;
	resetButtonOptions: ButtonOptions;
	submitButtonOptions: ButtonOptions;
	actionColOptions: ColEx;
	actionSpan: Number;
	isAdvanced: Boolean;
	hideAdvanceBtn: Boolean;
}

export const ActionPropsDefault = {
	showActionButtonGroup: true,
	showResetButton: true,
	showSubmitButton: true,
	showAdvancedButton: false,
	resetButtonOptions: {},
	submitButtonOptions: {},
	actionColOptions: {},
	actionSpan: 6
};

export interface ItemPropsType {
	schema: FormSchema;
	formProps: FormProps;
	initialValues: Recordable<any>;
	tableAction: TableActionType;
	formActionType: FormActionType;
	isAdvanced: Boolean;
}

export const ItemPropsDefault = {
	schema: {},
	formProps: {},
	initialValues: {}
};
